home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / MoreFiles 1.4.1 / IterateDirectory.h < prev    next >
Text File  |  1995-12-21  |  5KB  |  145 lines

  1. /*
  2. **    IterateDirectory: File Manager directory iterator routines.
  3. **
  4. **    by Jim Luther
  5. **
  6. **    File:        IterateDirectory.h
  7. **
  8. **    Copyright © 1995 Jim Luther
  9. **    All rights reserved.
  10. **
  11. **    You may incorporate this sample code into your applications without
  12. **    restriction, though the sample code has been provided "AS IS" and the
  13. **    responsibility for its operation is 100% yours.
  14. **
  15. **    IterateDirectory is designed to drop into the MoreFiles sample code
  16. **    library I wrote while in Apple Developer Technical Support
  17. */
  18.  
  19. #ifndef __ITERATEDIRECTORY__
  20. #define __ITERATEDIRECTORY__
  21.  
  22. #include <Types.h>
  23. #include <Files.h>
  24.  
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28.  
  29. /*****************************************************************************/
  30.  
  31. typedef    pascal    void (*IterateFilterProcPtr) (const CInfoPBRec * const cpbPtr,
  32.                                               Boolean *quitFlag,
  33.                                               void *yourDataPtr);
  34. /*    ¶ Prototype for the IterateFilterProc function IterateDirectory calls.
  35.     This is the prototype for the IterateFilterProc function which is
  36.     called once for each file and directory found by IterateDirectory. The
  37.     IterateFilterProc gets a pointer to the CInfoPBRec that IterateDirectory
  38.     used to call PBGetCatInfo. The IterateFilterProc can use the read-only
  39.     data in the CInfoPBRec for whatever it wants.
  40.     
  41.     If the IterateFilterProc wants to stop IterateDirectory, it can set
  42.     quitFlag to true (quitFlag will be passed to the IterateFilterProc
  43.     false).
  44.     
  45.     The yourDataPtr parameter can point to whatever data structure you might
  46.     want to access from within the IterateFilterProc.
  47.  
  48.     cpbPtr        input:    A pointer to the CInfoPBRec that IterateDirectory
  49.                         used to call PBGetCatInfo. The CInfoPBRec and the
  50.                         data it points to must not be changed by your
  51.                         IterateFilterProc.
  52.     quitFlag    output:    Your IterateFilterProc can set quitFlag to true
  53.                         if it wants to stop IterateDirectory.
  54.     yourDataPtr    input:    A pointer to whatever data structure you might
  55.                         want to access from within the IterateFilterProc.
  56.     
  57.     __________
  58.     
  59.     Also see:    IterateDirectory, FSpIterateDirectory
  60. */
  61.  
  62. #define CallIterateFilterProc(userRoutine, cpbPtr, quitFlag, yourDataPtr) \
  63.         (*(userRoutine))((cpbPtr), (quitFlag), (yourDataPtr))
  64.  
  65. /*****************************************************************************/
  66.  
  67. pascal    OSErr    IterateDirectory(short vRefNum,
  68.                                  long dirID,
  69.                                  StringPtr name,
  70.                                  unsigned short maxLevels,
  71.                                  IterateFilterProcPtr iterateFilter,
  72.                                  void *yourDataPtr);
  73. /*    ¶ Iterate (scan) through a directory's content.
  74.     The IterateDirectory function performs a recursive iteration (scan) of
  75.     the specified directory and calls your IterateFilterProc function once
  76.     for each file and directory found.
  77.     
  78.     The maxLevels parameter lets you control how deep the recursion goes.
  79.     If maxLevels is 1, IterateDirectory only scans the specified directory;
  80.     if maxLevels is 2, IterateDirectory scans the specified directory and
  81.     one subdirectory below the specified directory; etc. Set maxLevels to
  82.     zero to scan all levels.
  83.     
  84.     The yourDataPtr parameter can point to whatever data structure you might
  85.     want to access from within the IterateFilterProc.
  86.  
  87.     vRefNum            input:    Volume specification.
  88.     dirID            input:    Directory ID.
  89.     name            input:    Pointer to object name, or nil when dirID
  90.                             specifies a directory that's the object.
  91.     maxLevels        input:    Maximum number of directory levels to scan or
  92.                             zero to scan all directory levels.
  93.     iterateFilter    input:    A pointer to the routine you want called once
  94.                             for each file and directory found by
  95.                             IterateDirectory.
  96.     yourDataPtr        input:    A pointer to whatever data structure you might
  97.                             want to access from within the IterateFilterProc.
  98.     
  99.     __________
  100.     
  101.     See also:    IterateFilterProcPtr, FSpIterateDirectory
  102. */
  103.  
  104. /*****************************************************************************/
  105.  
  106. pascal    OSErr    FSpIterateDirectory(const FSSpec *spec,
  107.                                     unsigned short maxLevels,
  108.                                     IterateFilterProcPtr iterateFilter,
  109.                                     void *yourDataPtr);
  110. /*    ¶ Iterate (scan) through a directory's content.
  111.     The FSpIterateDirectory function performs a recursive iteration (scan)
  112.     of the specified directory and calls your IterateFilterProc function once
  113.     for each file and directory found.
  114.     
  115.     The maxLevels parameter lets you control how deep the recursion goes.
  116.     If maxLevels is 1, FSpIterateDirectory only scans the specified directory;
  117.     if maxLevels is 2, FSpIterateDirectory scans the specified directory and
  118.     one subdirectory below the specified directory; etc. Set maxLevels to
  119.     zero to scan all levels.
  120.     
  121.     The yourDataPtr parameter can point to whatever data structure you might
  122.     want to access from within the IterateFilterProc.
  123.  
  124.     spec            input:    An FSSpec record specifying the directory to scan.
  125.     maxLevels        input:    Maximum number of directory levels to scan or
  126.                             zero to scan all directory levels.
  127.     iterateFilter    input:    A pointer to the routine you want called once
  128.                             for each file and directory found by
  129.                             FSpIterateDirectory.
  130.     yourDataPtr        input:    A pointer to whatever data structure you might
  131.                             want to access from within the IterateFilterProc.
  132.     
  133.     __________
  134.     
  135.     See also:    IterateFilterProcPtr, IterateDirectory
  136. */
  137.  
  138. /*****************************************************************************/
  139.  
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143.  
  144. #endif    /* __ITERATEDIRECTORY__ */
  145.